#pragma once

#include <stdint.h>
#include <functional>
#include <memory>
#include "boost/asio.hpp"

// namespace boost {
// namespace asio {
//     class io_context;
// }
// }

namespace rr {
namespace nio {

class EventLoop
{
public:
    using Sptr = std::shared_ptr<EventLoop>;
    using PendingCallback = std::function<void()>;
    using Work      = boost::asio::executor_work_guard<boost::asio::io_context::executor_type>;
    using IoCtxSPtr = std::shared_ptr<boost::asio::io_context>;
public:
    EventLoop();
    ~EventLoop();

    int32_t Loop();
    void Quit();

    void RunInLoop(const PendingCallback& cb);

    IoCtxSPtr GetIoContextSptr() {  return io_ctx_; }
    boost::asio::io_context& GetIoContextRef() { return *(io_ctx_.get()); }

private:
    IoCtxSPtr io_ctx_;
    std::unique_ptr<Work> work_;
};


} //namespace 
} //namespace 
